package com.easyui.common;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.easyui.bean.Student;
import com.easyui.DB.ConnectDB;
import com.easyui.DB.OperateDB;

public class SelStudent {
	
	/**
	 * 得到初始化后的学Student对象
	 * @param sno
	 * @param sname
	 * @param sex
	 * @param major
	 * @param grade
	 * @param stype
	 * @return
	 */
	public Student getStudent(String sno, String sname, String sex, String major, String grade, String stype) {
		Student s = new Student(sno, sname, sex, major, grade, stype);
		return s;
	}
	
	/**
	 * 根据项目ID
	 * 返回参与学生信息链表
	 * @param pno
	 * @return
	 */
	public List<Map> getPMember(int pno) {
		List<Map> pMemberList = null;
		List<Object> plist = null;
		List<Map> initList = null;
		
		String sql = "select * from partake p, student s where p.sno = s.sno and pno = ?";
		
		plist = new ArrayList<Object>();
		plist.add(pno);
		OperateDB.setParmList(plist);
		
		initList = OperateDB.excuteQuery(sql);
		if(initList.size() > 0) {
			pMemberList = new ArrayList<Map>();
			for(int i=0; i<initList.size(); i++) {
				Map<String, String> map = initList.get(i);
				String sname = (String)map.get("sname");
				String stage = (String)map.get("stage");
				String sno = (String)map.get("sno");
				map.put("sno", sno);
				map.put("sname", sname);
				map.put("stage", stage);
				pMemberList.add(map);
			}
		}
		return pMemberList;
	}
	
	/**
	 * 获取所有学生数据
	 * 返回Map类型的链表
	 * @param orderBy
	 * @param sortName
	 * @return List
	 */
	public List<Map> getAllStudents(String orderBy, String sortName, Student s) {
		List<Map> initList = null;
		List<Object> plist = null;
		
System.out.println(orderBy);
System.out.println(sortName);
		
		String addSql = addWhere(s);
		String sql = "";
		if(addSql != null && !addSql.equals("")) {
			sql = "select * from student where 1=1 " + addSql + " order by " + sortName + " " + orderBy;
		} else {
			sql = "select * from student order by " + sortName + " " + orderBy;
		}
		
System.out.println(sql);
		OperateDB.setParmList(plist);//初始化paramList
		initList = OperateDB.excuteQuery(sql);
		
		return initList;
	}
	
	
	/**
	 * 获得指定工号的老师未管理的学生
	 * @param tno
	 * @param orderBy
	 * @param sortName
	 * @param s
	 * @return
	 */
	public List<Map> getNMStudents(String tno, String orderBy, String sortName, Student s) {
		List<Map> initList = null;
		List<Object> plist = null;
		
System.out.println(orderBy);
System.out.println(sortName);
		
		String addSql = addWhere(s);
		String sql = "";
		if(addSql != null && !addSql.equals("")) {
			sql = "select * from student " + 
					" where sno not in( " + 
						" select sno from manage " + 
						" where tno = '" + tno + "' ) " +
						addSql + " order by " + sortName + " " + orderBy;
		} else {
			sql = "select * from student " + 
					" where sno not in( " + 
						" select sno from manage " + 
						" where tno = '" + tno + "' ) order by " + sortName + " " + orderBy;
		}
		
System.out.println(sql);
		OperateDB.setParmList(plist);//初始化paramList
		initList = OperateDB.excuteQuery(sql);
		
		return initList;
	}
	
	/**
	 * 获得指定工号的老师已管理的学生
	 * @param tno
	 * @param orderBy
	 * @param sortName
	 * @param s
	 * @return
	 */
	public List<Map> getMStudents(String tno, String orderBy, String sortName, Student s) {
		List<Map> initList = null;
		List<Object> plist = null;
		
System.out.println(orderBy);
System.out.println(sortName);
		
		String addSql = addWhere(s);
		String sql = "";
		if(addSql != null && !addSql.equals("")) {
			sql = "select * from student " + 
					" where sno in( " + 
						" select sno from manage " + 
						" where tno = '" + tno + "' ) " +
						addSql + " order by " + sortName + " " + orderBy;
		} else {
			sql = "select * from student " + 
					" where sno in( " + 
						" select sno from manage " + 
						" where tno = '" + tno + "' ) order by " + sortName + " " + orderBy;
		}
		
System.out.println(sql);
		OperateDB.setParmList(plist);//初始化paramList
		initList = OperateDB.excuteQuery(sql);
		
		return initList;
	}
	
	/**
	 * 获得没有查询条件时管理的学生
	 * 不进行分页
	 * @param tno
	 * @param orderBy
	 * @param sortName
	 * @return
	 */
	public List<Student> getMStudents(String tno, String orderBy, String sortName) {
		List<Student> slist = null;
		List<Map> initList = null;
		List<Object> plist = null;
		
System.out.println(orderBy);
System.out.println(sortName);
		
		String sql = "";
		sql = "select * from student " + 
				" where sno in( " + 
					" select sno from manage " + 
					" where tno = '" + tno + "' ) order by " + sortName + " " + orderBy;
	
System.out.println(sql);
		OperateDB.setParmList(plist);//初始化paramList
		initList = OperateDB.excuteQuery(sql);
		
		if(initList != null && initList.size() > 0) {//有学生信息时
			slist = new ArrayList<Student>();
			for(int i=0; i<initList.size(); i++) {
				Map map = initList.get(i);
				Student s = new Student();
				s.init(map);
				slist.add(s);
			}
		}
		
		return slist;
	}
	
	/**
	 * 获得修改项目信息时可以添加的学生信息
	 * @param tno
	 * @param orderBy
	 * @param sortName
	 * @return
	 */
	public List<Student> getAddStudents(String tno, int pno, String orderBy, String sortName) {
		List<Student> slist = null;
		List<Map> initList = null;
		List<Object> plist = null;
		
System.out.println(orderBy);
System.out.println(sortName);
		
		String sql = "";
		sql = "select * from student " + 
				" where sno in( " +  
						" select sno from manage " +
						" where tno = '" + tno + "') " + 
					" and sno not in( " + 
						" select sno from partake " + 
						" where pno = " + pno + ") order by " + sortName + " " + orderBy;
System.out.println(sql);
		OperateDB.setParmList(plist);//初始化paramList
		initList = OperateDB.excuteQuery(sql);
		
		if(initList != null && initList.size() > 0) {//有学生信息时
			slist = new ArrayList<Student>();
			for(int i=0; i<initList.size(); i++) {
				Map map = initList.get(i);
				Student s = new Student();
				s.init(map);
				slist.add(s);
			}
		}
		
		return slist;
	}
	
	/**
	 * 获得指定页及每页大小的学生信息并按照指定字段排序
	 * 返回Student类型的链表
	 * @param page
	 * @param rows
	 * @param orderBy
	 * @param sortName
	 * @return
	 */
	public List<Student> getSpeStudents(List<Map> initList, int page, int rows, String orderBy, String sortName, Student st) {
		List<Student> slist = null;
		List<Map> finalList = null;
		List<Object> plist = null;
		
		if(initList != null && initList.size() > 0) {//有学生信息时
			int totalRecords = 0;
			int totalPage = 0;
			int pageSize = rows;//rows 一页显示几行
			int pageNo = page;//page 第几页
			
			totalRecords = initList.size();
			totalPage = (totalRecords + pageSize -1)/pageSize;
			if(totalPage < 1) {
				totalPage = 1;
			}
			int startPos = (pageNo -1) * pageSize;
			
			String addSql = addWhere(st);
			String sql = "";
			if(addSql != null && !addSql.equals("")) {
				sql = "select * from student where 1=1 " + addSql + " order by " + sortName + " " + orderBy + 
				" limit " + startPos + ", " + pageSize;
			} else {
				sql = "select * from student order by " + sortName + " " + orderBy + 
				" limit " + startPos + ", " + pageSize;
			}
			
			
System.out.println(sql);
			OperateDB.setParmList(plist);//初始化paramList
			finalList = OperateDB.excuteQuery(sql);
			
			if(finalList != null && finalList.size() > 0) {//有学生信息时
				slist = new ArrayList<Student>();
				for(int i=0; i<finalList.size(); i++) {
					Map map = finalList.get(i);
					Student s = new Student();
					s.init(map);
					slist.add(s);
				}
			}
		}
		
		return slist;
	}
	
	/**
	 * 获得指定工号的教师未管理的学生
	 * 返回指定页码和条件的学生链表
	 * @param initList
	 * @param tno
	 * @param page
	 * @param rows
	 * @param orderBy
	 * @param sortName
	 * @param st
	 * @return
	 */
	public List<Student> getSpeNMStudents(List<Map> initList, String tno, int page, int rows, String orderBy, String sortName, Student st) {
		List<Student> slist = null;
		List<Map> finalList = null;
		List<Object> plist = null;
		
		if(initList != null && initList.size() > 0) {//有学生信息时
			int totalRecords = 0;
			int totalPage = 0;
			int pageSize = rows;//rows 一页显示几行
			int pageNo = page;//page 第几页
			
			totalRecords = initList.size();
			totalPage = (totalRecords + pageSize -1)/pageSize;
			if(totalPage < 1) {
				totalPage = 1;
			}
			int startPos = (pageNo -1) * pageSize;
			
			String addSql = addWhere(st);
			String sql = "";
			if(addSql != null && !addSql.equals("")) {
				sql = "select * from student " + 
					" where sno not in( " + 
						" select sno from manage " + 
						" where tno = '" + tno + "' ) " +
						addSql + " order by " + sortName + " " + orderBy + 
						" limit " + startPos + ", " + pageSize;
			} else {
				sql = "select * from student " + 
					" where sno not in( " + 
						" select sno from manage " + 
						" where tno = '" + tno + "' ) order by " + sortName + " " + orderBy + 
						" limit " + startPos + ", " + pageSize;
			}
			
			
System.out.println(sql);
			OperateDB.setParmList(plist);//初始化paramList
			finalList = OperateDB.excuteQuery(sql);
			
			if(finalList != null && finalList.size() > 0) {//有学生信息时
				slist = new ArrayList<Student>();
				for(int i=0; i<finalList.size(); i++) {
					Map map = finalList.get(i);
					Student s = new Student();
					s.init(map);
					slist.add(s);
				}
			}
		}
		
		return slist;
	}
	
	/**
	 * 获得指定工号的教师已管理的学生
	 * 返回指定页码和条件的学生链表
	 * @param initList
	 * @param tno
	 * @param page
	 * @param rows
	 * @param orderBy
	 * @param sortName
	 * @param st
	 * @return
	 */
	public List<Student> getSpeMStudents(List<Map> initList, String tno, int page, int rows, String orderBy, String sortName, Student st) {
		List<Student> slist = null;
		List<Map> finalList = null;
		List<Object> plist = null;
		
		if(initList != null && initList.size() > 0) {//有学生信息时
			int totalRecords = 0;
			int totalPage = 0;
			int pageSize = rows;//rows 一页显示几行
			int pageNo = page;//page 第几页
			
			totalRecords = initList.size();
			totalPage = (totalRecords + pageSize -1)/pageSize;
			if(totalPage < 1) {
				totalPage = 1;
			}
			int startPos = (pageNo -1) * pageSize;
			
			String addSql = addWhere(st);
			String sql = "";
			if(addSql != null && !addSql.equals("")) {
				sql = "select * from student " + 
					" where sno in( " + 
						" select sno from manage " + 
						" where tno = '" + tno + "' ) " +
						addSql + " order by " + sortName + " " + orderBy + 
						" limit " + startPos + ", " + pageSize;
			} else {
				sql = "select * from student " + 
					" where sno in( " + 
						" select sno from manage " + 
						" where tno = '" + tno + "' ) order by " + sortName + " " + orderBy + 
						" limit " + startPos + ", " + pageSize;
			}
			
			
System.out.println(sql);
			OperateDB.setParmList(plist);//初始化paramList
			finalList = OperateDB.excuteQuery(sql);
			
			if(finalList != null && finalList.size() > 0) {//有学生信息时
				slist = new ArrayList<Student>();
				for(int i=0; i<finalList.size(); i++) {
					Map map = finalList.get(i);
					Student s = new Student();
					s.init(map);
					slist.add(s);
				}
			}
		}
		
		return slist;
	}
	

	
	/**
	 * 更新学生信息
	 * @param sno
	 * @param sname
	 * @param sex
	 * @param major
	 * @param grade
	 * @param stype
	 * @return
	 */
	public boolean updateStudent(String sno, String sname, String sex, String major, String grade, String stype) {
		List<Object> plist = null;
		boolean success = false;
		
		String	sql = "update student set sname = ?, sex = ?, major = ?, grade = ?, stype = ? " +
				" where sno = ?";

		plist = new ArrayList<Object>();	
		plist.add(sname);
		plist.add(sex);
		plist.add(major);
		plist.add(grade);
		plist.add(stype);
		plist.add(sno);
		OperateDB.setParmList(plist);//初始化paramList
		
		success = OperateDB.update(sql);
			
		return success;
	}
	
	/**
	 * admin添加学生用户
	 * @param tno
	 * @param tname
	 * @param sex
	 * @return
	 */
	public boolean addStudent(String sno, String sname, String sex, String major, String grade, String stype) {
		boolean success = true;
		
		Connection conn = ConnectDB.getConnection();
		boolean autoCommit = false;
		try {
			autoCommit = conn.getAutoCommit();
			conn.setAutoCommit(false);// 取消自动提交
			
			//向student插入数据
			if(insertStudent(conn,sno,sname,sex,major,grade,stype)) {
				if(new UserLogin().insertUser(conn, "student", sno)) {//向user表插入数据
					success = true;
				} else {
					success = false;
				}
			} else {
				success = false;
			}
			
		} catch (SQLException e) {
			success = false;
			System.out.println("添加学生失败，详情如下：\n");
			e.printStackTrace();
		} catch (NumberFormatException e) {
			success = false;
			System.out.println("数据格式化异常，详情如下：\n");
			e.printStackTrace();
		} finally {
			try {
				if (success) {
					conn.commit();//手动提交
				} else {
					conn.rollback();//回滚
				}
				conn.setAutoCommit(autoCommit);// 恢复现场
			} catch (SQLException e) {
				e.printStackTrace();
			}
			
			OperateDB.close(conn);
		}
		
		System.out.println("add:" + success);
		
		return success;
	}
	
	/**
	 * 插入学生信息
	 * @param sno
	 * @param sname
	 * @param sex
	 * @param major
	 * @param grade
	 * @param stype
	 * @return
	 */
	public boolean insertStudent(Connection conn, String sno, String sname, String sex, String major, String grade, String stype) {
		List<Object> plist = null;
		boolean success = false;
		
		String	sql = "insert into student values(?, ?, ?, ?, ?, ?)";
System.out.println(sql);

		plist = new ArrayList<Object>();	
		plist.add(sno);
		plist.add(sname);
		plist.add(sex);
		plist.add(major);
		plist.add(grade);
		plist.add(stype);
		OperateDB.setParmList(plist);//初始化paramList
		
		success = OperateDB.update(conn, sql);
			
		return success;
	}
	
	/**
	 * 删除指定sno的一组学生
	 * @param id
	 * @return
	 */
	public Map<String, Object> deleteStudent(String[] id) {
		Map<String, Object> result = new HashMap<String, Object>();
		List<Object> plist = null;
		boolean success = true;
		String msg = "";
		
		if (id.length < 1) {
			success = false;
			msg = "未选择删除数据.";
		} else {
			Connection conn = ConnectDB.getConnection();
			boolean autoCommit = false;
			try {
				autoCommit = conn.getAutoCommit();
				conn.setAutoCommit(false);// 取消自动提交

				for (int i = 0; i < id.length; i++) {
					if(canDelStudent(conn, id[i])) {	//是否可以删除,表partake、attachment、note中是否还有信息
						if(!deleteStudent(conn, id[i])) {//删除学生信息,包括表student、user、manage
							success = false;
							msg = "删除学生信息失败.";
							break; // 跳出循环
						} 
					} else {
						success = false;
						msg = "系统中还有学生信息，不能删除.";
						break; // 跳出循环
					}
				}

			} catch (SQLException e) {
				success = false;
				System.out.println("删除数据失败，详情如下：\n");
				e.printStackTrace();
			} catch (NumberFormatException e) {
				success = false;
				System.out.println("数据格式化异常，详情如下：\n");
				e.printStackTrace();
			} finally {
				try {
					if (success) {
						conn.commit();//手动提交
					} else {
						conn.rollback();//回滚
					}
					conn.setAutoCommit(autoCommit);// 恢复现场
				} catch (SQLException e) {
					e.printStackTrace();
				}
				
				OperateDB.close(conn);
			}
		}

		if(success) {
			msg = "删除学生信息成功";
		}
		
		result.put("success", success);
		result.put("msg", msg);
		
		return result;
	}
	
	/**
	 * 是否可以删除
	 * 表partake、attachment、note中是否还有信息
	 * @param conn
	 * @param sno
	 * @return
	 */
	public boolean canDelStudent(Connection conn, String sno) {
		List<Object> plist = null;
		boolean canDel = false;
		
		String sql = "";
		
		//partake表是否有信息
		sql = "select * from partake where sno = ?";
		plist = new ArrayList<Object>();	
		plist.add(sno);
		OperateDB.setParmList(plist);//初始化paramList
		
		List<Map> partakeList = null;
		partakeList = OperateDB.excuteQuery(conn, sql);
		
		if(partakeList != null && partakeList.size() > 0) {
			canDel = false;
		} else {	
			//note表是否有相关信息
			sql = "select * from note where pubtype = ? and pubno = ?";
			plist = new ArrayList<Object>();	
			plist.add("student");
			plist.add(sno);
			OperateDB.setParmList(plist);//初始化paramList
			
			List<Map> noteList = null;
			noteList = OperateDB.excuteQuery(conn, sql);
			
			if(noteList != null && noteList.size() > 0) {
				canDel = false;
			} else {	//attachment表是否有相关信息
				sql = "select * from attachment where uptype = ? and upno = ?";
				plist = new ArrayList<Object>();	
				plist.add("student");
				plist.add(sno);
				OperateDB.setParmList(plist);//初始化paramList
				
				List<Map> attachList = null;
				attachList = OperateDB.excuteQuery(sql);
				if(attachList != null && attachList.size() > 0) {
					canDel = false;
				} else {
					canDel = true;
				}
			}
		}
			
		return canDel;
	}
	
	/**
	 * 删除指定id的学生
	 * 从user表和student表、manage
	 * @param conn
	 * @param sno
	 * @return
	 */
	public boolean deleteStudent(Connection conn, String sno) {
		List<Object> plist = null;
		boolean success = false;
		String sql = "";
		
		//删除manage表中信息，可能没有相关信息
		sql = "delete from manage where sno = ?";
		plist = new ArrayList<Object>();	
		plist.add(sno);
		OperateDB.setParmList(plist);//初始化paramList
		
		if(!OperateDB.update(conn, sql)) {
			success = false;
		} else {
			//删除student表中信息
			sql = "delete from student where sno = ?"; 
			plist = new ArrayList<Object>();	
			plist.add(sno);
			OperateDB.setParmList(plist);//初始化paramList
			
			if(!OperateDB.update(conn, sql)) {
				success = false;
			} else {
				//删除user表中信息
				sql = "delete from user where role = ? and userID = ?";
				plist = new ArrayList<Object>();	
				plist.add("student");
				plist.add(sno);
				OperateDB.setParmList(plist);//初始化paramList
				
				success = OperateDB.update(conn, sql);
			}
		}
		
		return success;
	}
	
	/**
	 * 删除老师管理的学生
	 * @param id
	 * @param tno
	 * @return
	 */
	public Map<String, Object> deleteMStudent(String[] id, String tno) {
		Map<String, Object> result = new HashMap<String, Object>();
		List<Object> plist = null;
		boolean success = true;
		String msg = "";
		
		if (id.length < 1) {
			success = false;
			msg = "未选择删除数据.";
		} else {
			Connection conn = ConnectDB.getConnection();
			boolean autoCommit = false;
			try {
				autoCommit = conn.getAutoCommit();
				conn.setAutoCommit(false);// 取消自动提交
				
				for (int i = 0; i < id.length; i++) {
					if(canDelMStudent(conn, tno, id[i])) {	//是否可以删除,表partake中是否还有信息
						if(!deleteMStudent(conn, tno, id[i])) {//删除学生信息,表manage
							success = false;
							msg = "删除管理学生失败.";
							break; // 跳出循环
						} 
					} else {
						success = false;
						msg = "学生还有项目参与，不能删除.";
						break; // 跳出循环
					}
				}

			} catch (SQLException e) {
				success = false;
				System.out.println("删除数据失败，详情如下：\n");
				e.printStackTrace();
			} catch (NumberFormatException e) {
				success = false;
				System.out.println("数据格式化异常，详情如下：\n");
				e.printStackTrace();
			} finally {
				try {
					if (success) {
						conn.commit();//手动提交
					} else {
						conn.rollback();//回滚
					}
					conn.setAutoCommit(autoCommit);// 恢复现场
				} catch (SQLException e) {
					e.printStackTrace();
				}
				
				OperateDB.close(conn);
			}
		}
		
		if(success) {
			msg = "删除管理学生成功";
		}

		result.put("success", success);
		result.put("msg", msg);
		
		return result;
	}
	
	/**
	 * 删除指定教师管理的学生
	 * manage表
	 * @param conn
	 * @param tno
	 * @param sno
	 * @return
	 */
	public boolean deleteMStudent(Connection conn, String tno, String sno) {
		List<Object> plist = null;
		boolean success = false;
		String sql = "";
		
		//删除manage表中信息
		sql = "delete from manage where sno = ? and tno = ? ";
		plist = new ArrayList<Object>();	
		plist.add(sno);
		plist.add(tno);
		OperateDB.setParmList(plist);//初始化paramList
		
		if(!OperateDB.update(conn, sql)) {
			success = false;
		} else {
			success = true;
		}
		
		return success;
	}
	
	/**
	 * 能否删除指定老师管理的学生
	 * @param conn
	 * @param sno
	 * @return
	 */
	public boolean canDelMStudent(Connection conn, String tno, String sno) {
		List<Object> plist = null;
		boolean canDel = false;
		
		String sql = "";
		
		//partake表是参与该教师项目的信息
		sql = "select * from partake where sno = ? and pno in(select pno from project where pubno = ?)";
		plist = new ArrayList<Object>();	
		plist.add(sno);
		plist.add(tno);
		OperateDB.setParmList(plist);//初始化paramList
		
		List<Map> partakeList = null;
		partakeList = OperateDB.excuteQuery(conn, sql);
		
		if(partakeList != null && partakeList.size() > 0) {
			canDel = false;
		} else {	
			canDel = true;
		}
			
		return canDel;
	}
	
	
	/**
	 * 为教师添加学生进行管理
	 * @param id
	 * @param tno
	 * @return
	 */
	public boolean manageStudent(String []id, String tno) {
		List<Object> plist = null;
		boolean success = true;
		
		if (id.length < 1) {
			success = false;
		} else {
			Connection conn = ConnectDB.getConnection();
			boolean autoCommit = false;
			try {
				autoCommit = conn.getAutoCommit();
				conn.setAutoCommit(false);// 取消自动提交

				for (int i = 0; i < id.length; i++) {
					String sql = "insert into manage values(?,?)"; 
					plist = new ArrayList<Object>();	
					plist.add(id[i]);
					plist.add(tno);
					OperateDB.setParmList(plist);//初始化paramList
					
					if(!OperateDB.update(conn,sql)) {
						success = false;
						break; // 跳出循环
					} else {
						System.out.println("manage sno " + id[i] + " success");
					}
				}

			} catch (SQLException e) {
				success = false;
				System.out.println("插入数据失败，详情如下：\n");
				e.printStackTrace();
			} catch (NumberFormatException e) {
				success = false;
				System.out.println("数据格式化异常，详情如下：\n");
				e.printStackTrace();
			} finally {
				try {
					if (success) {
						conn.commit();//手动提交
					} else {
						conn.rollback();//回滚
					}
					conn.setAutoCommit(autoCommit);// 恢复现场
				} catch (SQLException e) {
					e.printStackTrace();
				}
				
				OperateDB.close(conn);
			}
		}

		return success;
	}
	
	/**
	 * 查询指定工号老师所管理的学生
	 * 返回链表
	 * @param tno
	 * @return
	 */
	public List<String> getStuList(String tno) {
		List<String> stuentList = null;
		List<Map> finalList = null;
		List<Object> plist = null;
		
		String sql = "select * from manage where tno = ? ";
System.out.println(sql);
		plist = new ArrayList<Object>();	
		plist.add(tno);
		OperateDB.setParmList(plist);//初始化paramList
			
		finalList = OperateDB.excuteQuery(sql);
			
		if(finalList != null && finalList.size() > 0) {//有学生信息时
			stuentList = new ArrayList<String>();
			for(int i=0; i<finalList.size(); i++) {
				Map map = finalList.get(i);
				String sno = (String)map.get("sno");
				stuentList.add(sno);
			}
		}
		
		return stuentList;
	}
	
	/**
	 * 获得分工
	 * @return
	 */
	public List<Map> getStype() {
		List<Map> stypeList = null;
		List<Object> plist = null;
		
		String sql = "select distinct(stype) from student";
		OperateDB.setParmList(plist);
		stypeList = OperateDB.excuteQuery(sql);
		
		return stypeList;
	}
	
	/**
	 * 增加查询条件
	 * @param s
	 * @return
	 */
	public String addWhere(Student s) {
		String addSql = "";
		String sno = s.getSno();
		String sname = s.getSname();
		String sex = s.getSex();
		String major = s.getMajor();
		String grade = s.getGrade();
		String stype = s.getStype();
		
		if(sno != null && !sno.equals("")) {
			addSql += " and sno like  '%" +  sno + "%' ";
		}
		if(sname != null && !sname.equals("")) {
			addSql += " and sname like '%" +  sname + "%'";
		}
		if(sex != null && !sex.equals("")) {
			addSql += " and sex = '" +  sex + " '";
		}
		if(major != null && !major.equals("")) {
			addSql += " and major like '%" +  major + "%'";
		}
		if(grade != null && !grade.equals("")) {
			addSql += " and grade = '" +  grade + " '";
		}
		
		if(stype != null && !stype.equals("")) {
			addSql += " and stype like '%" +  stype + "%'";
		}
		
		return addSql;
	}
}
